package com.efesco.crm.crm;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * serviceMaterialViewModel
 */
public class serviceMaterialViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters)
      throws Exception {
   Dataset ds=getDataset("dataset_service_material");
   DBStatement dbs=new DBStatement();
   String task=parameters.getString("task");
   if(task.equals("save"))
   com.efesco.common.CommUtil.UpdateData(ds, "s_service_material", "service_material_id");
   if(task.equals("delmark")){
	   ds.moveFirst();
	   while(!ds.isLast()){
		   if(ds.getCurrent().getBoolean("select")){
			   dbs.setSql("update s_service_material set deleted='"+ds.getCurrent().getString("deleted")+"',del_date=sysdate where SERVICE_MATERIAL_ID="+ds.getCurrent().getString("SERVICE_MATERIAL_ID"));
			   dbs.execute();
		   }
		   ds.moveNext();
	   }

   }
   if(task.equals("delete")){
	   ds.moveFirst();
	   while(!ds.isLast()){
		   if(ds.getCurrent().getBoolean("select")){
			   dbs.setSql("delete from s_service_material where SERVICE_MATERIAL_ID="+ds.getCurrent().getString("SERVICE_MATERIAL_ID"));
			   dbs.execute();
			   dbs.setSql("delete from s_employee_material where SERVICE_MATERIAL_ID="+ds.getCurrent().getString("SERVICE_MATERIAL_ID"));
			   dbs.execute();
		   }
		   ds.moveNext();
	   }	   
   }
  dbs.close();
  }

}
